﻿
using SDT.ServiceSystem;
using SDT.DataService.Services;

namespace SDT.CrawlSystem.Servers
{
    /// <summary>
    /// Written by TungNX
    /// </summary>
    public sealed class WebWorkUnit : WorkUnit
    {
        #region Results
        private string rawHtml = "";
        public string RawHtml
        {
            get { lock(this) return Ready ? rawHtml : null; }
            internal set { lock(this) rawHtml = value; }
        }
        private PageService svPage = new PageService();
        private LinkDownloadService svImg = new LinkDownloadService();
        
        public override void ClearResult()
        {
            lock (this)
            {
                RawHtml = null;
                Ready = true;
            }
        }

        internal bool ChangeStatus(UrlLoader.Status stt)
        {
            return svPage.ChangeStatus(uid, (byte)stt);
          
        }
        #endregion

        #region Data members
        private int uid = 0;
        public int Uid
        {
            get { return uid; }
        }

        private int cid = 0;
        public int ChannelId
        {
            get { return cid; }
        }

        private int pid = 0;
        public int PageId
        {
            get { return pid; }
        }

        private string url = "";
        public string Url
        {
            get { return url; }
        }

        private UrlLoader uFilter = null;
        public UrlLoader TheUFilter
        {
            get { return uFilter; }
        }

      
        #endregion

        public WebWorkUnit(int uid, int channelId, UrlLoader uFilter, string url)
            : base()
        {
            this.uFilter = uFilter;
            this.uid = uid;
            this.cid = channelId;
            this.pid = uFilter.PID;
            this.url = uFilter.Prefix + url;
        }
    }
}